#version 150

#moj_import <fog.glsl>
#moj_import <global.glsl>

uniform sampler2D Sampler0;

uniform vec4 ColorModulator;
uniform float FogStart;
uniform float FogEnd;
uniform vec4 FogColor;

in float vertexDistance;
in vec2 texCoord0;
in vec4 vertexColor;

out vec4 fragColor;

void main() {
    vec4 color = texture(Sampler0, texCoord0) * vertexColor * ColorModulator;
    if (color.a < 0.1) {
        discard;
    }
    fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor);
    
    float alpha = textureLod(Sampler0, texCoord0, 0.0).a * 255.0;
	if(check_alpha(alpha,OVERLAY_ALPHA)||check_alpha(alpha,POTION_ALPHA)){//potion overlayey
		vec2 Coord;float n;float m;
		//custom potions
			n = OVERLAY_SIZE / UNIT_SIZE - 1.0;
			m = OVERLAY_SIZE / UNIT_SIZE - 1.0;
			Coord = vec2(texCoord0.x, texCoord0.y) / (OVERLAY_SIZE / UNIT_SIZE) + vec2(n / (UNIT_SIZE * 4.0), m / (UNIT_SIZE * 4.0));
			fragColor = texture(Sampler0, Coord) * ColorModulator;
			if(check_alpha(textureLod(Sampler0, Coord, 0.0).a * 255.0, POTION_ALPHA)){
				vec4 color = texture(Sampler0, Coord) * vertexColor * ColorModulator;
				if (color.a < 0.1) discard;
				fragColor = linear_fog(color, vertexDistance, FogStart, FogEnd, FogColor);
			}
		//background
		if(check_rgb(fragColor.rgb,vec3(0,255,0)/255))discard;
	}
}
